<template>
    <div>
        <div class="goods_list" >
            <div class="goods_item" v-for="item in goodslist" :key="item.id" @click=getRouter(item.id)>
                <img :src="item.img_url" alt="">
                <h1>{{item.title}}</h1>
                <div class="info">
                    <p class="peice">
                        <span class="now">￥{{item.sell_price}}</span>
                        <span class="old">￥{{item.market_price}}</span>
                    </p>
                    <p class="sell">
                        <span>热卖中</span>
                        <span>剩下{{item.stock_quantity}}件</span>
                    </p>
                </div>
            </div>
            
        </div>
        <mt-button type="danger" size="large" @click="getmore_goods">加载更多</mt-button>
       
    </div>
</template>
<script>
export default {
    data(){
        return {
            number:1,
            goodslist:[]
        }
    },
    created(){
        this.getgoodslist();
    },
    methods:{
        getgoodslist(){
            this.$http.get("api/getgoods?pageindex="+this.number).then(
                result =>{
                    if(result.body.status===0){
                        this.goodslist = this.goodslist.concat(result.body.message)
                    }//concat拼接数组的方法
                }
            )
        },
        getmore_goods(){
            this.number++
            this.getgoodslist();
        },
        // 编程式路由
        getRouter(id){
            this.$router.push("/home/goodsinfo/"+id)
        }
    }
}
</script>
<style lang="scss" scoped>
    .goods_list{
        display:flex;
        flex-wrap: wrap;
        padding: 6px;
        justify-content: space-between;
        .goods_item{
            box-shadow: 0 0 10px #ccc;
            width:49%;
            margin-bottom:6px;
           
            img{
                width:100%;
                min-height: 177px;
            }
            h1{
                font-size:12px;
            }
            .info{
                background-color:#ccc;
                .now{
                    color:red;
                }
                .old {
                    text-decoration: line-through;
                }
                .sell{
                    display: flex;
                    justify-content: space-between;
                    margin:0;
                }
            }
        }

    }
</style>
